package com.duan.laugh.common.security.util;

import com.alibaba.ttl.TransmittableThreadLocal;
import lombok.experimental.UtilityClass;

/**
 * TTL用户
 */
@UtilityClass
public class UserContextHolder {
    private final ThreadLocal<LaughUser> THREAD_LOCAL_USER = new TransmittableThreadLocal<>();


    /**
     * TTL设置用户
     *
     * @param laughUser
     */
    public void set(LaughUser laughUser) {
        THREAD_LOCAL_USER.set(laughUser);
    }

    /**
     * 获取TTL中的用户
     *
     * @return
     */
    public LaughUser get() {
        return THREAD_LOCAL_USER.get();
    }

    /**
     * 清除TTL中的用户
     */
    public void clear() {
        THREAD_LOCAL_USER.remove();
    }
}
